\defmodule{TimeUnit}

Represents a time unit for conversion of time durations.
A time unit instance can be used to get information about
the time unit and as a selector to perform conversions.
Each time unit has a short name used when representing a time unit,
a full descriptive name, and the number of hours corresponding to one unit.

\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        TimeUnit
 * Description:  Represents a time unit for conversion of time durations.
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.util;


public enum TimeUnit\begin{hide} {
\end{hide}\end{code}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {enum values}
\begin{code}

   NANOSECOND\begin{hide}

("ns", "nanosecond", 1.0/3600000000000.0),
\end{hide}
\end{code}
\begin{tabb}   Represents a nanosecond which has short name \texttt{ns}.
\end{tabb}
\begin{code}

   MICROSECOND\begin{hide}

("us", "microsecond", 1.0/3600000000.0),
\end{hide}
\end{code}
\begin{tabb}   Represents a microsecond which has short name \texttt{us}.
\end{tabb}
\begin{code}

   MILLISECOND\begin{hide}

("ms", "millisecond", 1.0/3600000.0),
\end{hide}
\end{code}
\begin{tabb}   Represents a millisecond which has short name \texttt{ms}.
\end{tabb}
\begin{code}

   SECOND\begin{hide}

("s", "second", 1.0/3600.0),
\end{hide}
\end{code}
\begin{tabb}   Represents a second which has short name \texttt{s}.
\end{tabb}
\begin{code}

   MINUTE\begin{hide}

("min", "minute", 1.0/60.0),
\end{hide}
\end{code}
\begin{tabb}   Represents a minute which has short name \texttt{min}.
\end{tabb}
\begin{code}

   HOUR\begin{hide}

("h", "hour", 1.0),
\end{hide}
\end{code}
\begin{tabb}   Represents an hour which has short name \texttt{h}.
\end{tabb}
\begin{code}

   DAY\begin{hide}

("d", "day", 24.0),
\end{hide}
\end{code}
\begin{tabb}   Represents a day which has short name \texttt{d}.
\end{tabb}
\begin{code}

   WEEK\begin{hide}

("w", "week", 24.0*7);
\end{hide}
\end{code}
\begin{tabb}   Represents a week which has short name \texttt{w}.
\end{tabb}
\begin{code}\begin{hide}

   private String shortName;
   private String longName;
   private transient double numHours;

   private TimeUnit (String shortName, String longName, double numHours) {
      this.shortName = shortName;
      this.longName = longName;
      this.numHours = numHours;
   }\end{hide}
\end{code}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Methods}
\begin{code}

   public String getShortName()\begin{hide} {
      return shortName;
   }\end{hide}
\end{code}
\begin{tabb}   Returns the short name representing this unit in
 a string specifying a time duration.
\end{tabb}
\begin{htmlonly}
   \return{the short name of this time unit.}
\end{htmlonly}
\begin{code}

   public String getLongName()\begin{hide} {
      return longName;
   }\end{hide}
\end{code}
\begin{tabb}   Returns the long name of this time unit.
\end{tabb}
\begin{htmlonly}
   \return{the long name of this time unit.}
\end{htmlonly}
\begin{code}

   public String toString()\begin{hide} {
      return longName;
   }\end{hide}
\end{code}
\begin{tabb}   Calls \method{getLongName}{()}.
\end{tabb}
\begin{htmlonly}
   \return{the result of \method{getLongName}{()}.}
\end{htmlonly}
\begin{code}

   public double getHours()\begin{hide} {
      return numHours;
   }\end{hide}
\end{code}
\begin{tabb}   Returns this time unit represented in hours.
 This returns the number of hours corresponding to
 one unit.
\end{tabb}
\begin{htmlonly}
   \return{the time unit represented in hours.}
\end{htmlonly}
\begin{code}

   public static double convert (double value, TimeUnit srcUnit,
                                 TimeUnit dstUnit)\begin{hide} {
      double hours = value*srcUnit.getHours();
      return hours/dstUnit.getHours();
   }
}\end{hide}
\end{code}
\begin{tabb}   Converts \texttt{value} expressed in time unit \texttt{srcUnit} to
 a time duration expressed in \texttt{dstUnit} and returns
 the result of the conversion.
\end{tabb}
\begin{htmlonly}
   \param{value}{the value being converted.}
   \param{srcUnit}{the source time unit.}
   \param{dstUnit}{the destination time unit.}
   \return{the converted value.}
   \exception{NullPointerException}{if \texttt{srcUnit} or
    \texttt{dstUnit} are \texttt{null}.}
\end{htmlonly}
